package gov.kqqzyyy.monkey.radiologyscreen.ui;

import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v7.app.AppCompatActivity;

import gov.kqqzyyy.monkey.radiologyscreen.R;

public class SplashActivity extends AppCompatActivity {

    private static final int SHOW_TIME = 800; //过渡界面展示时间
    private Thread startThread;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
    }

    @Override
    protected void onResume() {
        super.onResume();

        if (startThread == null) {
            startThread = new Thread(() -> {
                SystemClock.sleep(SHOW_TIME);
                Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                startActivity(intent);
                overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

            });
            startThread.start();
        }

    }


    @Override
    protected void onStop() {
        super.onStop();
        stopThread();
        finish();
    }

    private void stopThread() {
        if (startThread != null && startThread.isAlive()) {
            startThread.interrupt();
            startThread = null;
        }
    }
}
